<?php

/**
 * This is the model class for table "ab_category".
 *
 * The followings are the available columns in table 'ab_category':
 * @property integer $Id
 * @property string $category_title
 * @property integer $category_order
 * @property integer $category_type
 */
class Category extends CActiveRecord
{
	const C_PAGE=0;
	const C_ART=1;
	const C_AB=2;
	const C_SERV=3;
	const C_OTH=4;
	/**
	 * Returns the static model of the specified AR class.
	 * @return Category the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'ab_category';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('category_order, category_type', 'numerical', 'integerOnly'=>true),
			array('category_title', 'length', 'max'=>50),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('Id, category_title, category_order, category_type', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'Id' => '编号',
			'category_title' => '分类名称',
			'category_order' => '排序',
			'category_type' => '项目类别',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('Id',$this->Id);
		$criteria->compare('category_title',$this->category_title,true);
		$criteria->compare('category_order',$this->category_order);
		$criteria->compare('category_type',$this->category_type);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
	
	public function getCategoryTypes()
	{
		return array(
		self::C_PAGE => "普通页面",
		self::C_ART => "文章信息",
		self::C_AB => "抗体",
		self::C_SERV => "技术服务",
		self::C_OTH => "其他",
		);
	}
	public function getCategoryTypeText()
	{
		$array = $this->getCategoryTypes();
		return $array[$this->category_type];
	}
}